<template>
	<view class="contents" :style="'height:'+screenHeight+'px'">
		<!-- <view class="none" v-if="showlist==true">
			<view class="">
				
				<view class="" v-for="(item,index) in Mymedical" :key="index">
						<view class="list" >
							<view class="leftlist">
								<view class="date">
									<span>{{splitetext(item.TJCreateDatetime)}}</span>
								
								</view>
								<view class="lefttop">
									<span class="textleft" style="color: black;">姓名:</span>
									<span class="textright"  style="color: black;">{{item.TJName}}</span>
								</view>
								<view class="lefttop">
									<span class="textleft"  style="color: black;">身份证:</span>
									<span class="textright" style="color: black;" >{{item.TJIDCardNo}}</span>
								</view>
								<view class="lefttop">
									<span class="textleft"  style="color: black;">手机号:</span>
									<span class="textright"  style="color: black;">{{item.TJPhoneNo}}</span>
								</view>
								<u-line class="u-line"></u-line>
								<view class="centerButton">
									<u-button size="mini" class="buttonwidth" :hair-line="false" :custom-style="{border:'none'}"   @click="deletes(item.TJChildId)">删除</u-button>
									<u-button size="mini"  class="buttonwidth" :hair-line="false" :custom-style="{border:'none'}"  @click="deletes2(item.TJChildId)">修改</u-button>
									<u-button size="mini" class="buttonwidth" :hair-line="false" :custom-style="{border:'none'}"  @click="subscribe(item)">预约体检</u-button>
								</view>
						
							</view>
					
						</view>
						
				</view>
			</view>
		</view> -->



		<view class="middle" v-if="show">
			<view class="body" v-for="(item,index) in Mymedical" :key="index">
				<view class="leftf">
					<!-- <view class="date">
						<span>{{66}}</span>

					</view> -->
					<view class="cardcontent">
						<view class="information">
							<view class="gray">套餐名称：<span class="black">{{item.tcname}}</span></view>
							<view class="gray">预约时间：<span class="black">{{item.djdate}}</span></view>
						</view>
						<u-line class="u-line"></u-line>
						<view class="centerButton">
							<u-button size="mini" class="buttonwidth" :hair-line="false" :custom-style="{border:'none'}"
								@click="showReport(item.tjid)">查看体检报告</u-button>

						</view>
					</view>


				</view>
			</view>
			<!-- 	<view class="bottom-button">
				<view class="button bacnone2" @click="visit">暂无体检报告</view>
			</view> -->
		</view>
		<view class="none" v-else>
			<view class="coent">
				<u-empty text="暂无体检报告" mode="list" icon-size="200">
				</u-empty>
			</view>
		</view>


		<u-modal v-model="deleteshow" confirm-color='#0197F6' :content="content" show-cancel-button="true"
			@confirm="confirm" @cancel="deleteshow==false" mask-close-able="true"></u-modal>

		<u-modal v-model="deleteshow2" confirm-color='#0197F6' :content="content2" show-cancel-button="true"
			@confirm="confirm2" @cancel="deleteshow2==false" mask-close-able="true"></u-modal>

	</view>
</template>

<script>
	import {
		mapState,
		mapGetters
	} from 'vuex'

	export default {
		data() {
			return {
				screenHeight: getApp().globalData.screenHeight - 44,
				showdfault: false,
				deleteshow: false,
				deleteshow2: false,
				titlefault: '设置默认就诊人',
				contentdfault: '确认切换默认就诊人吗',
				title: '删除就诊卡',
				content: '删除之后不可恢复，是否确认',
				content2: '正在前往修改界面，是否确认',
				showlist: false,
				show: true,
				remove: true,

				Mymedical: [],
				list: {
					type: 'default',
					message: "删除成功",
				},
				add: {
					type: 'default',
					message: "切换成功",
				},
				list2: {
					type: 'default',
					message: "删除失败",
				},
				doctor: [],
				PatientId: '',
				//doctorinfor: '',
				doctlist: [],
				item: {
					TJName: "",
					TJIDCardNo: "",
					TJPhoneNo: "",
				},



			}
		},
		// onBackPress(event) {
		// 	uni.switchTab({
		// 		url: '/pages/index/index'
		// 	});
		// 	return true;
		// },

		computed: {
			...mapState(['token'], ['userInfo']),
			...mapGetters(['hasLogin', 'getUserInfo'])
		},
		onLoad(option) {


			this.item.TJName = option.TJName
			this.item.TJIDCardNo = option.TJIDCardNo
			this.item.TJPhoneNo = option.TJPhoneNo

			//	console.log("option.OrderId", option.OrderId)
			//this.getDetail()
		},
		onShow() {
			if (this.hasLogin) {
				uni.showLoading({
					title: '加载中'
				})
				this.$store.dispatch('getUserInfo');
				this.getlist()
			} else {
				uni.hideLoading();
				uni.showModal({
					title: '提示',
					content: '登录后才可以操作',
					confirmText: '去登录',
					showCancel: false,
					success: function(res) {
						uni.reLaunch({
							url: '/pages/auth/login'
						})
					}
				});
				return;
			}

		},
		methods: {
			// splitetext(text) {
			// 	console.log(text)
			// 	let temp = text + ''
			// 	temp = Number.parseInt((temp.split("T")[0].split('-')[1])) + "月" + temp.split("T")[0].split('-')[2] + "日"
			// 	return temp


			// },
			showReport(item) {
				let li
				this.$request('TJReport', 'GetReportPdf', {
					tjid: item,
				}).then(res => {
					if (res.code == 1) {
						li = "http://139.129.167.131:59034" + res.data.resultdata
						
						console.log(li);
						if (this.isWeiXin()) {
						
						
							window.location.href = li //验证token
						} else {
							uni.showLoading({
								title: '加载中'
							})
							open(li);
							uni.hideLoading()
						}
					} else {
						uni.showToast({
							title: "查看失败",
							icon: "none",
							duration: 2000,
						});
					}
				})



				
				
			},
			isWeiXin() {
				var ua = window.navigator.userAgent.toLowerCase();
				if (ua.match(/MicroMessenger/i) == 'micromessenger') {
					return true;
				} else {
					return false;
				}
			},
			deletes2(PatientId) {
				this.deleteshow2 = true
				this.PatientId = PatientId
				console.log(PatientId)

			},
			subscribe(item) {
				console.log(item);

				uni.navigateTo({
					//保留当前页面，跳转到应用内的某个页面
					url: `/pages/MedicalExamination/Subscribe/Subscribe?TJChildId=${item.TJChildId}&TJName=${item.TJName}`,
				})


			},
			cutclient(item) {




				uni.switchTab({
					//保留当前页面，跳转到应用内的某个页面
					url: `/pages/index/index?sortI=${item}`,
					success: function(e) {
						console.log("目标页面加载成功,携带参数并触发事件")
						uni.$emit('sortI', item)
					}
				})


			},


			getlist() {

				console.log(this.item.TJName)
				console.log(this.item.TJIDCardNo)
				console.log(this.item.TJPhoneNo)
				this.$request('TJReport', 'GetReport', {
					Name:this.item.TJName,
					IDcard: this.item.TJIDCardNo,
					Phone:this.item.TJPhoneNo,
				}).then(res => {

					if (res.code == 1) {


						this.Mymedical = res.data.resultdata
						//console.log("this",this.Mymedical.length)
						if (this.Mymedical.length >= 1) {
							//console.log("进了")
							this.show = true
							this.showlist = true
							//console.log(this.showlist)
						} else {

							this.show = false

						}


					} else {


						this.show = false
					}
					uni.hideLoading();
				})
			},
			// successlist(item) {
			// 	let items = JSON.stringify(item)
			// 	let doctorinfors = this.doctorinfor
			// 	let doctlist = this.doctlist
			// 	uni.redirectTo({
			// 		url: `/pages/register/Scheduling/confirm/confirm?items=${items}&doctorinfor=${doctorinfors}&doctlist=${doctlist}`,
			// 		fail(error) {
			// 			console.log(error)
			// 		}
			// 	})
			// },
			showToast(params) {
				this.$refs.uToast.show({
					...params,
					complete() {
						params.url && uni.navigateTo({
							url: params.url
						})
					}
				})
			},
			confirm() {
				console.log(this.PatientId)
				uni.showLoading({
					title: '正在删除'
				})
				this.$request('TJChildBase', 'DelchildBase', {
					TJChildId: this.PatientId
				}).then(res => {
					console.log(res)
					if (res.code == 1) {
						uni.hideLoading();
						//this.showToast(this.list)
						this.getlist()
					} else {
						uni.hideLoading();
						//this.showToast(this.list2)
					}
				})

				this.deleteshow = false
			},

			confirm2() {
				console.log(this.PatientId)
				uni.showLoading({
					title: '跳转'
				})
				uni.navigateTo({
					//保留当前页面，跳转到应用内的某个页面
					url: `/pages/MedicalExamination/AddUser/AddUser?PatientId=${this.PatientId}`,
				})

				this.deleteshow = false
			},
			// deletes(PatientId) {
			// 	this.deleteshow = true
			// 	this.PatientId = PatientId
			// 	console.log(PatientId)

			// },
			visit() {
				uni.redirectTo({
					url: `/pages/MedicalExamination/AddUser/AddUser`,
					fail(error) {
						console.log(error)
					}
				})
			},
			addvisit() {
				this.show = true
			},
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				// console.log('close');
			}
		}
	}
</script>

<style>
	@import './ReportDetail.css'
</style>
<style lang="scss">
	.u-page {
		padding: 0;
	}

	.u-cell-icon {
		width: 36rpx;
		height: 36rpx;
		margin-right: 8rpx;
	}

	.u-cell-group__title__text {
		font-weight: bold;
	}
</style>